package top.tungsword.webconsole.controller.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.tungsword.webconsole.biz.param.UserParam;
import top.tungsword.webconsole.biz.response.WebReturnInfo;
import top.tungsword.webconsole.biz.service.user.UserBiz;
import top.tungsword.webconsole.dal.entity.SsoUser;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserBiz userBiz;

    /**
     * 画面跳转
     * @return
     */
    @GetMapping("/userinfo")
    public String userInfo(ModelMap model, UserParam param){
        List<SsoUser> ssoUserList = userBiz.findUserList(param);
        model.addAttribute("ssoUserList", ssoUserList);
        model.addAttribute("userParam", param);
        return "user/userinfo";
    }

    @PostMapping("/addUser")
    @ResponseBody
    public WebReturnInfo<String> addUser(SsoUser param){
        return userBiz.addUser(param);
    }

    @PostMapping("/deleteUser")
    @ResponseBody
    public WebReturnInfo<String> deleteUser(SsoUser param){
        return userBiz.deleteUser(param);
    }

    @PostMapping("/updateUser")
    @ResponseBody
    public WebReturnInfo<String> updateUser(SsoUser param){
        return userBiz.updateUser(param);
    }
}
